From 0207b91bee98bdb2e3cf5bf1391cef2141e607df Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Wed, 25 Apr 2007 16:14:20 +0100 Subject: [PATCH] [XEND] Make existing autoplug classes implement new XendBase signed-off-by: Tom Wilkie --- tools/python/xen/xend/XendPBD.py | 118 ++++++++++-------- tools/python/xen/xend/XendPIFMetrics.py | 40 +++--- tools/python/xen/xend/XendQCoWStorageRepo.py | 2 +- .../python/xen/xend/XendStorageRepository.py | 2 +- tools/python/xen/xend/XendVMMetrics.py | 57 ++++----- 5 files changed, 116 insertions(+), 103 deletions(-) diff --git a/tools/python/xen/xend/XendPBD.py b/tools/python/xen/xend/XendPBD.py index 0eab82781c..10d8c32b81 100644 --- a/tools/python/xen/xend/XendPBD.py +++ b/tools/python/xen/xend/XendPBD.py @@ -18,62 +18,82 @@ import uuid from XendLogging import log +from xen.xend.XendBase import XendBase +from xen.xend import XendAPIStore +class XendPBD(XendBase): + """Physical block devices.""" -attr_inst = ['uuid', - 'host', - 'SR', - 'device_config'] -attr_ro = attr_inst + ['currently_attached'] - - -_all = {} - - -def get(ref): - return _all[ref] - - -def get_all(): - return _all.values() - - -def get_all_refs(): - return _all.keys() - - -def get_by_SR(sr_ref): - return [k for (k, v) in _all.items() if v.get_SR() == sr_ref] + def getClass(self): + return "PBD" + + def getAttrRO(self): + attrRO = ['host', + 'SR', + 'device_config', + 'currently_attached'] + return XendBase.getAttrRO() + attrRO + + def getAttrRW(self): + attrRW = [] + return XendBase.getAttrRW() + attrRW + + def getAttrInst(self): + return ['uuid', + 'host', + 'SR', + 'device_config'] + + def getMethods(self): + methods = ['destroy'] + return XendBase.getMethods() + methods + + def getFuncs(self): + funcs = ['create', + 'get_by_SR'] + return XendBase.getFuncs() + funcs + + getClass = classmethod(getClass) + getAttrRO = classmethod(getAttrRO) + getAttrRW = classmethod(getAttrRW) + getAttrInst = classmethod(getAttrInst) + getMethods = classmethod(getMethods) + getFuncs = classmethod(getFuncs) + + def recreate(uuid, record): + pbd = XendPBD(uuid, record) + return uuid + + def create(cls, record): + uuid = genuuid.createString() + pbd = XendPBD(uuid, record) + return uuid + create = classmethod(create) + + def __init__(self, uuid, record): + XendBase.__init__(self, uuid, record) + this.currently_attached = True -class XendPBD: - """Physical block devices.""" + def get_host(self): + return this.host - def __init__(self, record): - if 'uuid' not in record: - record['uuid'] = uuid.createString() + def get_SR(self): + return this.SR - import XendAPI - for v in attr_inst: - setattr(self, v, record[v]) - self.currently_attached = True - _all[record['uuid']] = self + def get_device_config(self): + return this.device_config + def get_currently_attached(self): + return this.currently_attached def destroy(self): - if self.uuid in _all: - del _all[self.uuid] - - - def get_record(self): - import XendAPI - result = {} - for v in attr_ro: - result[v] = getattr(self, v) - return result - + pass + + def get_by_SR(cls, sr_ref): + pbds = XendAPIStore.get_all("PBD") + return [pbd.get_uuid() + for pbd in pbds + if pbd.get_SR() == sr_ref] -for v in attr_ro: - def f(v_): - setattr(XendPBD, 'get_' + v_, lambda s: getattr(s, v_)) - f(v) + get_by_SR = classmethod(get_by_SR) diff --git a/tools/python/xen/xend/XendPIFMetrics.py b/tools/python/xen/xend/XendPIFMetrics.py index a94736c234..aca808384c 100644 --- a/tools/python/xen/xend/XendPIFMetrics.py +++ b/tools/python/xen/xend/XendPIFMetrics.py @@ -15,15 +15,30 @@ # Copyright (c) 2006-2007 Xensource Inc. #============================================================================ +from XendBase import XendBase -class XendPIFMetrics: +class XendPIFMetrics(XendBase): """PIF Metrics.""" + + def getClass(self): + return "PIF_metrics" - def __init__(self, uuid): - self.uuid = uuid + def getAttrRO(self): + attrRO = ['io_read_kbs', + 'io_write_kbs', + 'last_updated', + 'pif'] + return XendBase.getAttrRO() + attrRO + + getClass = classmethod(getClass) + getAttrRO = classmethod(getAttrRO) - def set_PIF(self, pif): - self.pif = pif + def __init__(self, uuid, pif_uuid): + XendBase.__init__(self, uuid, {}) + self.pif_uuid = pif_uuid + + def get_pif(self): + return self.pif_uuid def get_io_read_kbs(self): return self._get_stat(0) @@ -33,19 +48,12 @@ class XendPIFMetrics: def _get_stat(self, n): from xen.xend.XendNode import instance as xennode - pifname = self.pif.device - pifs_util = xennode().monitor.get_pifs_util() - if pifname in pifs_util: - return pifs_util[pifname][n] + #pifname = self.pif.device + #pifs_util = xennode().monitor.get_pifs_util() + #if pifname in pifs_util: + # return pifs_util[pifname][n] return 0.0 def get_last_updated(self): import xen.xend.XendAPI as XendAPI return XendAPI.now() - - def get_record(self): - return {'uuid' : self.uuid, - 'io_read_kbs' : self.get_io_read_kbs(), - 'io_write_kbs' : self.get_io_write_kbs(), - 'last_updated' : self.get_last_updated(), - } diff --git a/tools/python/xen/xend/XendQCoWStorageRepo.py b/tools/python/xen/xend/XendQCoWStorageRepo.py index 425b4f7eca..281559b762 100644 --- a/tools/python/xen/xend/XendQCoWStorageRepo.py +++ b/tools/python/xen/xend/XendQCoWStorageRepo.py @@ -30,7 +30,7 @@ import struct from xen.util import mkdir import uuid -import XendPBD +from XendPBD import XendPBD from XendError import XendError from XendVDI import * from XendTask import XendTask diff --git a/tools/python/xen/xend/XendStorageRepository.py b/tools/python/xen/xend/XendStorageRepository.py index 1e096cdf91..d37e6586a8 100644 --- a/tools/python/xen/xend/XendStorageRepository.py +++ b/tools/python/xen/xend/XendStorageRepository.py @@ -24,7 +24,7 @@ import sys from XendError import XendError from XendVDI import * -import XendPBD +from XendPBD import XendPBD XEND_STORAGE_NO_MAXIMUM = sys.maxint diff --git a/tools/python/xen/xend/XendVMMetrics.py b/tools/python/xen/xend/XendVMMetrics.py index d32a295de5..8328340ca9 100644 --- a/tools/python/xen/xend/XendVMMetrics.py +++ b/tools/python/xen/xend/XendVMMetrics.py @@ -17,38 +17,36 @@ #============================================================================ from xen.xend.XendLogging import log +from xen.xend.XendBase import XendBase import xen.lowlevel.xc xc = xen.lowlevel.xc.xc() -instances = {} - -class XendVMMetrics: +class XendVMMetrics(XendBase): """VM Metrics.""" - def get_by_uuid(_, uuid): - return instances[uuid] - - get_by_uuid = classmethod(get_by_uuid) - - def is_valid_vm_metrics(_, uuid): - return uuid in instances - - is_valid_vm_metrics = classmethod(is_valid_vm_metrics) - - def get_all(_): - return instances.keys() + def getClass(self): + return "VM_metrics" + + def getAttrRO(self): + attrRO = ['memory_actual', + 'VCPUs_number', + 'VCPUs_utilisation', + 'VCPUs_CPU', + 'VCPUs_flags', + 'VCPUs_params', + 'state', + 'start_time', + 'last_updated'] + return XendBase.getAttrRO() + attrRO + + getClass = classmethod(getClass) + getAttrRO = classmethod(getAttrRO) - get_all = classmethod(get_all) - def __init__(self, uuid, xend_domain_instance): - self.uuid = uuid + XendBase.__init__(self, uuid, {}) self.xend_domain_instance = xend_domain_instance - instances[uuid] = self - - def get_uuid(self): - return self.uuid - + def get_memory_actual(self): domInfo = self.xend_domain_instance.getDomInfo() if domInfo: @@ -145,16 +143,3 @@ class XendVMMetrics: def get_last_updated(self): import xen.xend.XendAPI as XendAPI return XendAPI.now() - - def get_record(self): - return { 'uuid' : self.uuid, - 'memory_actual' : self.get_memory_actual(), - 'VCPUs_number' : self.get_VCPUs_number(), - 'VCPUs_utilisation' : self.get_VCPUs_utilisation(), - 'VCPUs_CPU' : self.get_VCPUs_CPU(), - 'VCPUs_flags' : self.get_VCPUs_flags(), - 'VCPUs_params' : self.get_VCPUs_params(), - 'start_time' : self.get_start_time(), - 'state' : self.get_state(), - 'last_updated' : self.get_last_updated(), - } -- 2.30.2